#ifndef ADIS1654X_DATA_ACCESS_H
#define ADIS1654X_DATA_ACCESS_H

// has delta channels
#define ADIS_HAS_DELTA_BURST

// has calibration scale channel
#define ADIS_HAS_CALIB_SCALE

#define ADIS_FLS_MEM_ENDURANCE 100000
#define ADIS_MAX_SAMP_FREQ 4250.0

// value to add to reg addr per page
#define ADIS_PAGE_ID_VAL 0x80

// global commands
#define ADIS_GLOB_CMD_PAGE_ID 0x03
#define ADIS_GLOB_CMD_ADDR_WITHOUT_PAGE 0x02
#define ADIS_GLOB_CMD_ADDR \
  (ADIS_PAGE_ID_VAL * ADIS_PT_OF_PERC_PAGE_ID + ADIS_GLOB_CMD_ADDR_WITHOUT_PAGE)

#define ADIS_BIAS_CORRECTION_UPDATE_POS 0
#define ADIS_SENSOR_SELF_TEST_POS 1
#define ADIS_FLASH_MEMORY_UPDATE_POS 3
#define ADIS_FACTORY_CALIBRATION_RESTORE_POS 6
#define ADIS_SOFTWARE_RESET_CMD_POS 7

#define ADIS_BIAS_CORRECTION_UPDATE (1 << ADIS_BIAS_CORRECTION_UPDATE_POS)
#define ADIS_SENSOR_SELF_TEST (1 << ADIS_SENSOR_SELF_TEST_POS)
#define ADIS_FLASH_MEMORY_UPDATE (1 << ADIS_FLASH_MEMORY_UPDATE_POS)
#define ADIS_FACTORY_CALIBRATION_RESTORE (1 << ADIS_FACTORY_CALIBRATION_RESTORE_POS)
#define ADIS_SOFTWARE_RESET_CMD (1 << ADIS_SOFTWARE_RESET_CMD_POS)

// status and error flag indication
#define ADIS_DIAG_STAT_PAGE_ID 0x00
#define ADIS_DIAG_STAT_ADDR_WITHOUT_PAGE 0x08
#define ADIS_DIAG_STAT_ADDR \
  (ADIS_PAGE_ID_VAL * ADIS_DIAG_STAT_PAGE_ID + ADIS_DIAG_STAT_ADDR_WITHOUT_PAGE)
#define ADIS_MEM_FAIL_POS 1
#define ADIS_CRC_ERROR_POS 2
#define ADIS_SPI_COMM_ERR_POS 3
#define ADIS_SNSR_FAIL_POS 5
#define ADIS_FLS_MEM_UPDATE_FAIL_POS 6
#define ADIS_DATA_PATH_OVERRUN_POS 7
#define ADIS_CLK_ERR_POS 8
#define ADIS_WDG_TIMER_FLAG_POS 15

#define ADIS_MEM_FAIL (1 << ADIS_MEM_FAIL_POS)
#define ADIS_CRC_ERROR (1 << ADIS_CRC_ERROR_POS)
#define ADIS_SPI_COMM_ERR (1 << ADIS_SPI_COMM_ERR_POS)
#define ADIS_SNSR_FAIL (1 << ADIS_SNSR_FAIL_POS)
#define ADIS_FLS_MEM_UPDATE_FAIL (1 << ADIS_FLS_MEM_UPDATE_FAIL_POS)
#define ADIS_DATA_PATH_OVERRUN (1 << ADIS_DATA_PATH_OVERRUN_POS)
#define ADIS_CLK_ERR (1 << ADIS_CLK_ERR_POS)
#define ADIS_WDG_TIMER_FLAG (1 << ADIS_WDG_TIMER_FLAG_POS)

// self test error flags
#define ADIS_DIAG_STS_PAGE_ID 0x00
#define ADIS_DIAG_STS_REG_WITHOUT_PAGE 0x0A
#define ADIS_DIAG_STS_REG \
  (ADIS_PAGE_ID_VAL * ADIS_DIAG_STS_PAGE_ID + ADIS_DIAG_STS_REG_WITHOUT_PAGE)

#define ADIS_GYRO_ACCEL_FAIL_REG ADIS_DIAG_STS_REG
#define ADIS_GYRO_X_FAIL_POS 0
#define ADIS_GYRO_Y_FAIL_POS 1
#define ADIS_GYRO_Z_FAIL_POS 2
#define ADIS_ACCEL_X_FAIL_POS 3
#define ADIS_ACCEL_Y_FAIL_POS 4
#define ADIS_ACCEL_Z_FAIL_POS 5

#define ADIS_GYRO_X_FAIL (1 << ADIS_GYRO_X_FAIL_POS)
#define ADIS_GYRO_Y_FAIL (1 << ADIS_GYRO_Y_FAIL_POS)
#define ADIS_GYRO_Z_FAIL (1 << ADIS_GYRO_Z_FAIL_POS)
#define ADIS_ACCEL_X_FAIL (1 << ADIS_ACCEL_X_FAIL_POS)
#define ADIS_ACCEL_Y_FAIL (1 << ADIS_ACCEL_Y_FAIL_POS)
#define ADIS_ACCEL_Z_FAIL (1 << ADIS_ACCEL_Z_FAIL_POS)

// measurement range identifier
#define ADIS_RANG_MDL_PAGE_ID 0x03
#define ADIS_RANG_MDL_ADDR_WITHOUT_PAGE 0x12
#define ADIS_RANG_MDL_ADDR \
  (ADIS_PAGE_ID_VAL * ADIS_RANG_MDL_PAGE_ID + ADIS_RANG_MDL_ADDR_WITHOUT_PAGE)
#define ADIS_GYRO_MEAS_RANG_POS 2
#define ADIS_GYRO_MEAS_RANG (3 << ADIS_GYRO_MEAS_RANG_POS)

// point of percussion
#define ADIS_PT_OF_PERC_PAGE_ID 0x03
#define ADIS_PT_OF_PERC_REG_ADDR_WITHOUT_PAGE 0x0A
#define ADIS_PT_OF_PERC_REG_ADDR \
  (ADIS_PAGE_ID_VAL * ADIS_PT_OF_PERC_PAGE_ID + ADIS_PT_OF_PERC_REG_ADDR_WITHOUT_PAGE)
#define ADIS_PT_OF_PERC_ALGNMNT_POS 6
#define ADIS_PT_OF_PERC_ALGNMNT (1 << ADIS_PT_OF_PERC_ALGNMNT_POS)

// continuous bias estimation
#define ADIS_NULL_CNFG_PAGE_ID 0x03
#define ADIS_NULL_CNFG_ADDR_WITHOUT_PAGE 0x0E
#define ADIS_NULL_CNFG_ADDR \
  (ADIS_PAGE_ID_VAL * ADIS_NULL_CNFG_PAGE_ID + ADIS_NULL_CNFG_ADDR_WITHOUT_PAGE)

#define ADIS_TIME_BASE_CONTROL_POS 0
#define ADIS_X_AXIS_GYRO_BIAS_CORR_EN_POS 8
#define ADIS_Y_AXIS_GYRO_BIAS_CORR_EN_POS 9
#define ADIS_Z_AXIS_GYRO_BIAS_CORR_EN_POS 10
#define ADIS_X_AXIS_ACCEL_BIAS_CORR_EN_POS 11
#define ADIS_Y_AXIS_ACCEL_BIAS_CORR_EN_POS 12
#define ADIS_Z_AXIS_ACCEL_BIAS_CORR_EN_POS 13

#define ADIS_TIME_BASE_CONTROL 0xF
#define ADIS_X_AXIS_GYRO_BIAS_CORR_EN (1 << ADIS_X_AXIS_GYRO_BIAS_CORR_EN_POS)
#define ADIS_Y_AXIS_GYRO_BIAS_CORR_EN (1 << ADIS_Y_AXIS_GYRO_BIAS_CORR_EN_POS)
#define ADIS_Z_AXIS_GYRO_BIAS_CORR_EN (1 << ADIS_Z_AXIS_GYRO_BIAS_CORR_EN_POS)
#define ADIS_X_AXIS_ACCEL_BIAS_CORR_EN (1 << ADIS_X_AXIS_ACCEL_BIAS_CORR_EN_POS)
#define ADIS_Y_AXIS_ACCEL_BIAS_CORR_EN (1 << ADIS_Y_AXIS_ACCEL_BIAS_CORR_EN_POS)
#define ADIS_Z_AXIS_ACCEL_BIAS_CORR_EN (1 << ADIS_Z_AXIS_ACCEL_BIAS_CORR_EN_POS)

#endif
